package com.yh.homestay.service.impl;

import com.yh.homestay.dao.SysRoleMapper;
import com.yh.homestay.dao.SysStaffRoleMapper;
import com.yh.homestay.pojo.SysRole;
import com.yh.homestay.pojo.SysStaffRole;
import com.yh.homestay.service.SysRoleServiceG;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName SysRoleServiceImpl
 * @Description TODO
 * @Author GCL
 * @Date 2020/1/6 19:01
 */
@Service
public class SysRoleServiceImplG implements SysRoleServiceG {

    @Autowired
    private SysStaffRoleMapper sysStaffRoleMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    /**
    * @Date: 2020/1/6 19:03
    * @Description: 查询出登录用户的role 工号+姓名
    * @param staffId
    * @return: java.util.List<java.lang.String>
    */
    @Override
    public List<String> getRoleName(Integer staffId) {
        Example example = new Example(SysStaffRole.class);
        example.createCriteria().andEqualTo("staffId",staffId);
        List<SysStaffRole> staffRoles = sysStaffRoleMapper.selectByExample(example);
        List<String> roles = new ArrayList<String>();
        for (SysStaffRole staffRole:staffRoles) {
            SysRole sysRole = sysRoleMapper.selectByPrimaryKey(staffRole.getRoleId());
            roles.add(sysRole.getRoleName());
        }
        return roles;
    }
}
